package com.wego.service.impl;

import com.github.pagehelper.Page;
import com.wego.common.base.impl.BaseServiceImpl;
import com.wego.common.bean.PageBean;
import com.wego.entity.domain.Goods;
import com.wego.entity.domain.User;
import com.wego.entity.query.GoodsQuery;
import com.wego.entity.query.UserQuery;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wego.mapper.GoodsMapper;
import com.wego.service.GoodsService;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @className: GoodsServiceImpl
 * @description: TODO 类描述 
 * @author: Kuangkeli
 * @date: 2023/07/10 17:01
 **/

@Service
public class GoodsServiceImpl extends BaseServiceImpl<Goods> implements GoodsService{

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public PageBean<Goods> selectPage(GoodsQuery goodsQuery) {
        //设置分页信息
        Page<Goods> page = goodsQuery.toPage();
        //查询数据
        goodsMapper.selectList(goodsQuery);
        //将MyBatis提供的Page对象转换成我们自己的PageBean对象
        return new PageBean<>(page);
    }

    @Override
    public int selectCount(Goods goods) {
        return goodsMapper.selectCount(goods);
    }

    @Override
    public List<Goods> selectRecommend(String keywords) {
        final Example example = new Example(Goods.class);
        example.selectProperties("id","name","pic","price1","price2","sellingPoint","info");
        example.createCriteria()
                .orLike("name","%"+keywords+"%")
                .orLike("sellingPoint","%"+keywords+"%")
                .orLike("info","%"+keywords+"%");
        final List<Goods> goodsList = goodsMapper.selectByExampleAndRowBounds(example, new RowBounds(0, 20));

        return goodsList;
    }


}
